﻿using WRJClient.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WRJClient.Common
{
    public sealed class ControlCenterManager : DataManager<ControlCenterViewModel>
    {
        private static readonly ControlCenterManager _instance = new ControlCenterManager();
        public static ControlCenterManager Instance { get { return _instance; } }
        private ControlCenterManager() { }
        public int Count { get { return _datas.Count(); } }

        protected override bool addChild(ControlCenterViewModel t)
        {
            var vm = _datas.FirstOrDefault(m => m.StaticData.DbId == t.StaticData.DbId);
            if (vm == null)
            {
                _datas.Add(t);
                return true;
            }
            return false;
        }

        protected override bool removeChild(ControlCenterViewModel t)
        {
            var vm = _datas.FirstOrDefault(m => m.StaticData.DbId == t.StaticData.DbId);
            if (vm != null)
            {
                vm.RemoveGraphics();
                _datas.Remove(vm);
                return true;
            }
            return false;
        }

        public override ControlCenterViewModel Get(string dbId)
        {
            return _datas.FirstOrDefault(m => m.StaticData.DbId == dbId);
        }
        public ControlCenterViewModel GetById(string workStationId)
        {
            return _datas.FirstOrDefault(m => m.StaticData.WorkStationId == workStationId);
        }
    }
}
